﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MsgSender
{
    public partial class Form1 : Form
    {

        SerialPort sp = new SerialPort("COM21", 9600);
        public Form1()
        {
            InitializeComponent();
            sp.Open();
        }

        private void btnSendMsg_Click(object sender, EventArgs e)
        {
            
            string sendMsg = tbMsg.Text;
            byte[] msgByte = new byte[sendMsg.Length / 2];
        
            for (int i = 0; i < sendMsg.Length/2; i++)
            {
                byte msg;
                msg=Convert.ToByte(sendMsg.Substring(i*2, 2), 16);
                msgByte[i] = msg;
            }
            sp.Write(msgByte, 0, msgByte.Length);
        }
    }
}
